package com.ruoyi.web.controller.erp.transportation;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.erp.transportation.domain.Transportation;
import com.ruoyi.erp.transportation.service.TransportationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author QiuRongYu@itcast.cn
 * @version 1.0
 * @date 2020/12/14
 */
@Api(tags = "运输方式")
@RestController
@RequestMapping("/transportation")
public class TransportationController extends BaseController {
    private String prefix = "erp/transportation";
    @Resource
    private TransportationService transportationService;


    @GetMapping()
    public String getList() {
        return prefix + "/list";
    }

//    @GetMapping("/addList")
//    public String addList()
//    {
//        return prefix + "/addList";
//}
//    @GetMapping("/edit")
//    public String edit()
//    {
//        return prefix + "/edit";
//    }

    @PreAuthorize("@ss.hasPermi('transportation:transportation:export')")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Transportation transportation)
    {
        List<Transportation> transportationList = transportationService.selectList(transportation);
        ExcelUtil<Transportation> util = new ExcelUtil<Transportation>(Transportation.class);
        return util.exportExcel(transportationList, "运输方式代码数据");
    }
//
    /**
     * 根据id删除
     */
    @PreAuthorize("@ss.hasPermi('transportation:transportation:remove')")
    @PostMapping("/remove/{ids}")
    @ResponseBody
    public AjaxResult remove(@PathVariable("ids") String ids){
        transportationService.remove(ids);
        return AjaxResult.success("删除成功");
    }
    /**
     * 修改运输方式代码
     */
    @PreAuthorize("@ss.hasPermi('transportation:transportation:edit')")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult edittransportation(@RequestBody Transportation transportation) {
            transportationService.edittransportation(transportation);
            return AjaxResult.success("修改成功");
    }
    /**
  * 根据id查询运输详情
  */
  @GetMapping("/gettransportation/{id}")
  public AjaxResult transportationselect(@PathVariable("id") String shipViaCode) {
//      Transportation transportation=transportationService.transportationselect(shipViaCode);
      AjaxResult ajax = AjaxResult.success();
      if (StringUtils.isNotNull(shipViaCode))
      {
          ajax.put(AjaxResult.DATA_TAG, transportationService.transportationselect(shipViaCode));
      }
      return ajax;
  }
    /**
     * 新增运输列表
     */
    @PreAuthorize("@ss.hasPermi('transportation:transportation:add')")
    @PostMapping("/addList")
    @ResponseBody
    public AjaxResult transportationAdd(@RequestBody Transportation transportation){
        transportationService.transportationAdd(transportation);
        return AjaxResult.success("添加成功");
    }
//    /**
//     * 查询所有的运输模式列表
//     */
//    @PostMapping("/transportationMode")
//    @ResponseBody
//    public TableDataInfo transportationMode() {
//         return null;
//    }
//    @ApiOperation("运输单位类型查询条件")
//    @RequestMapping(value = "selectTransportUnitTypeAll",method = {RequestMethod.POST})
//    @ResponseBody
//    public TableDataInfo selectTransportUnitTypeAll(){
//        return getDataTable(transportUnitTypeService.selectTransportUnitTypeAll(null,null,null,null,null,null));
//}
    /**
     * 查询运输列表
     */
    @ApiOperation(value="查询列表")
    @PostMapping("/transportationList")
    @ResponseBody
    public TableDataInfo transportationList( Transportation transportation){
        List<Transportation> list= transportationService.transportationList(transportation);
        return  getDataTable(list);
    }}

